use std::sync::Arc;

pub use honeybee::message::{
    AllUserMessageApp, AllUserMessageForward, GmsgForward, UmsgForward, UserMessageApp,
    UserMessageForward,
};
use honeybee::prelude::{gmsg_db, netmessage, umsg_db, MessageRegister};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

#[netmessage(id = 1, result = "()")]
pub struct UscUserRegister {
    pub uid: i64,
    pub session_key: String,
    pub sequence_id: u128,
    pub app_node: String,
}

#[netmessage(id = 2, result = "()")]
pub struct UscUserUnregister {
    pub uid: i64,
    pub session_key: String,
}

#[netmessage(id = 3, result = "()")]
pub struct UscRepeatOnlineKickout {
    pub session_key: String,
}

#[netmessage(id = 4)]
pub struct NewUmsgNotify {
    pub object_id: String,
    pub msg_type: umsg_db::UmsgType,
    pub msg_bytes: Vec<u8>,
}

#[netmessage(id = 5)]
#[derive(Clone)]
pub struct NewGmsgNotify {
    pub object_id: String,
    pub msg_type: gmsg_db::GmsgType,
    pub msg_bytes: Vec<u8>,
    pub expire_time: i64,
}

#[netmessage(id = 101)]
pub struct RspHelloWorld {
    pub a: f32,
    pub b: Vec<String>,
}

#[netmessage(id = 102, result = "u32")]
pub struct Add(pub u32, pub u32);

#[netmessage(id = 103, result = "Vec<String>")]
pub struct GetValue;

#[derive(Debug, Serialize, Deserialize)]
pub struct Scores {
    pub scores: Vec<u32>,
}
#[netmessage(id = 104, result = "Scores")]
pub struct GetScores;

#[netmessage(id = 105)]
pub struct ReqHelloWorld {
    pub a: f32,
    pub b: Vec<String>,
}

#[netmessage(id = 106)]
pub struct UserOnlineNotifyRoom {
    pub uid: i64,
}

#[netmessage(id = 107)]
pub struct RoomChangeAppUserData {
    pub a: u32,
}

#[netmessage(id = 108)]
pub struct LocalUscAppTest {}

#[netmessage(id = 109)]
pub struct NatsMsgTest {
    pub data: String,
}

static MESSAGE_REGISTER: Lazy<Arc<MessageRegister>> = Lazy::new(|| {
    let mut register = MessageRegister::new();
    register.register_rpc::<UscUserRegister>();
    register.register_rpc::<UscUserUnregister>();
    register.register::<UserMessageForward>();
    register.register::<AllUserMessageForward>();
    register.register::<UserMessageApp>();
    register.register::<AllUserMessageApp>();
    register.register::<UmsgForward>();
    register.register::<GmsgForward>();
    register.register::<NewGmsgNotify>();
    register.register::<ReqHelloWorld>();
    register.register::<RspHelloWorld>();
    register.register::<UserOnlineNotifyRoom>();
    register.register::<LocalUscAppTest>();
    register.register_rpc::<Add>();
    register.register_rpc::<GetValue>();
    register.register_rpc::<GetScores>();
    register.register_nats::<NatsMsgTest>();
    Arc::new(register)
});

pub fn get_message_register() -> Arc<MessageRegister> {
    MESSAGE_REGISTER.clone()
}
